package cn.cvs.service;

import cn.cvs.dao.ContactMapper;
import cn.cvs.pojo.Contact;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContactServiceImpl implements ContactService{
    @Autowired
    private ContactMapper mapper;
    @Override
    public List<Contact> list(String cname, Integer pageIndex, Integer pageSize) {
        int startIndex = (pageIndex - 1) * pageSize;
        return mapper.list(cname,startIndex,pageSize);
    }

    @Override
    public Integer add(Contact contact) {
        return mapper.add(contact);
    }

    @Override
    public Integer pageCount(String cname, Integer pageSize) {
        int pageCount = mapper.pageCount(cname) % pageSize > 0 ? mapper.pageCount(cname) / pageSize + 1: mapper.pageCount(cname) / pageSize;
        return pageCount;
    }

    @Override
    public Integer update(Contact contact) {
        return mapper.update(contact);
    }

    @Override
    public Contact getContact(Integer id) {
        return mapper.getContact(id);
    }

    @Override
    public Integer del(Integer id) {
        return mapper.del(id);
    }
}
